<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WISSC轮滑教培服务网-查询系统</title>
    <#assign base=request.contextPath  />
    <link rel="icon" href="${base}/favicon.ico">
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>
    <script type="text/javascript" src="${base}/js/feng.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/css/hzw-city-picker.css">
    <script type="text/javascript" src="${base}/js/city-data.js"></script>
    <script type="text/javascript" src="${base}/js/hzw-city-picker.min.js"></script>
    <script type="text/javascript" src="${base}/js/city-zk.js"></script>
    <script type="text/javascript" src="${base}/js/province.js"></script>
</head>
<script>
    var defaults = {
        s1: 'provid',
        s2: 'cityid',
        s3: 'areaid',
        v1: null,
        v2: null,
        v3: null
    };
</script>
<body>
<form class="layui-form" action="" style="margin: 10px">
    <input type="hidden" id="id" value="${id}"/>

    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;战队名称</label>
        <div class="layui-input-inline">
            <input name="teamName" id="teamName" lay-verify="required" autocomplete="off" class="layui-input isNull"
                   type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;建队时间</label>
        <div class="layui-input-inline">
            <input name="buildingTime" id="buildingTime" lay-verify="required" autocomplete="off"
                   class="layui-input isNull" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;战队等级</label>
        <div class="layui-input-inline">
            <select name="teamLevel" lay-verify="required" id="teamLevel" class=" isNull">
                <option value="">请选择</option>
                <option value="1">一级战队</option>
                <option value="2">二级战队</option>
                <option value="3">三级战队</option>
                <option value="4">四级战队</option>
                <option value="5">五级战队</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;选择地区</label>
            <div class="layui-input-inline">
                <select name="provid" id="provid" lay-filter="provid" lay-verify="required" class="isNull">
                    <option value="">请选择国家</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="cityid" id="cityid" lay-filter="cityid" lay-verify="required">
                    <option value="">请选择省</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="areaid" id="areaid" lay-filter="areaid" lay-verify="required">
                    <option value="">请选择市</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;是否参加过城市排名</label>
        <div class="layui-input-inline">
            <select name="cityRanking" lay-verify="required" id="cityRanking" class=" isNull">
                <option value="">请选择</option>
                <option value="1">是</option>
                <option value="2">否</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;是否参加省份排名</label>
        <div class="layui-input-inline">
            <select name="provinceRanking" lay-verify="required" id="provinceRanking" class=" isNull">
                <option value="">请选择</option>
                <option value="1">是</option>
                <option value="2">否</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;是否参加国家排名</label>
        <div class="layui-input-inline">
            <select name="nationalRanking" lay-verify="required" id="nationalRanking" class=" isNull">
                <option value="">请选择</option>
                <option value="1">是</option>
                <option value="2">否</option>
            </select>
        </div>
    </div>
    <div class="" id="demo"></div>
    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test1" style="background-color: #0092EF;">战队lodo</button>
        <div class="layui-upload-list" id="teamLogo">
            <img src="${base}/team/getPhoto?path=${teamLogo}" id="demo1" style="width:80px;height:80px"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <button class="layui-btn " lay-submit lay-filter="formDemo" type="button" onclick="onSubmit()"
                    id="aa" style="background-color: #0092EF;">立即提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary ">重置</button>
        </div>
    </div>
</form>

<script>


    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '${base}/file/uploadFile'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //上传成功
                //alert(res.data);
                aa = res.data;
                return res.data;
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })
</script>
<script type="text/javascript">
    var cityPicker = new HzwCityPicker({
        data: data,
        target: 'cityChoice',
        valType: 'k',
        hideCityInput: {
            name: 'city',
            id: 'city'
        },
        hideProvinceInput: {
            name: 'areaId',
            id: 'areaId',
            val: 'q'
        },
        callback: function () {
        }
    });

    cityPicker.init();
    var idFlag = 0;
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        laydate.render({
            elem: '#buildingTime' //指定元素
        });


        function timeAdd() {
            lay('.datetime').each(function () {
                laydate.render({
                    elem: this,
                    trigger: 'click'
                });
            });
        }

        $(function () {
            $.ajax({
                type: "POST",
                traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
                url: "${base}/team/getTeamCity",
                data: {id: $("#id").val()},
                success: function (data) {
                    var arr = data.str.split("/");
                    var arr1 = data.sum.split("=");
                    for (var i = 0; i < arr1.length - 1; i++) {
                        var arr2 = arr1[i].split(",");
                        if (arr2[0] != "null") {
                            for (var j = 0; j < 1; j++) {
                                $("#demo").append(
                                    '<div class="layui-form-item">' +
                                    '<div class="layui-inline">' +
                                    '<input id= "indId' + idFlag + '" type="hidden" value= "' + arr2[0] + '"/>' +
                                    '<label class="layui-form-label"><a style="color:red">*</a>赛事日期</label>' +
                                    '<div class="layui-input-inline">' +
                                    '<input name="matchTime" id="matchTime' + idFlag + '"  value="' + arr2[1] + '" lay-verify="required" autocomplete="off" class="layui-input isNull datetime"  type="text">' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="layui-inline">' +
                                    '<label class="layui-form-label"><a style="color:red">*</a>赛事名称</label>' +
                                    '<div class="layui-input-inline">' +
                                    '<input name="matchName" id="matchName' + idFlag + '" value="' + arr2[2] + '" lay-verify="required" autocomplete="off" class="layui-input isNull"' + 'type="text">' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="layui-inline">' +
                                    '<label class="layui-form-label"><a style="color:red">*</a>获得名次</label>' +
                                    '<div class="layui-input-inline">' +
                                    '<input name="ranking" id="ranking' + idFlag + '" value="' + arr2[3] + '" lay-verify="required" autocomplete="off" class="layui-input isNull"' + 'type="text">' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="layui-inline">' +
                                    '<label class="layui-form-label"><a style="color:red">*</a>获得积分</label>' +
                                    '<div class="layui-input-inline">' +
                                    '<input name="integral" id="integral' + idFlag + '" value="' + arr2[4] + '" lay-verify="required" autocomplete="off" class="layui-input isNull"' + 'type="text">' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>')
                                idFlag += 1;
                                form.render();
                                timeAdd();
                            }
                        } else {
                            break;
                        }
                    }
                    if (arr != null && arr != "") {
                        for (var i = 0; i < arr.length; i++) {
                            if (i == 0) {
                                $("#provid").find("option:contains('" + arr[i] + "')").attr("selected", true);
                            }
                            if (i == 1) {
                                $("#cityid").append("<option selected='selected' value='" + arr[i] + "' >" + arr[i] + "</option>");
                            }
                            if (i == 2) {
                                $("#areaid").append("<option selected='selected' value='" + arr[i] + "' >" + arr[i] + "</option>");
                            }
                        }

                    }
                    form.render('select');
                }

            });

        })
    });

</script>
<script>
    //编辑
    var aa;
    var bb = "";

    function onSubmit() {
        if (!isNull()){
            return;
        }
        var provid = $("#provid").val()
        var cityid = $("#cityid").val();
        var areaid = JSON.stringify($("#areaid").val());
        var str = areaid.replace(/^\"|\"$/g, '');
        var sum = provid + "/" + cityid + "/" + str + "/";
        var jsonData = {};
        jsonData.teamName = $("#teamName").val();
        jsonData.buildingTime = (new Date($("#buildingTime").val())).getTime();
        jsonData.city = sum;
        if (aa == undefined) {
            jsonData.teamLogo = "${teamLogo}";
        } else {
            jsonData.teamLogo = aa;
        }
        jsonData.teamLevel = $("#teamLevel").val();
        jsonData.cityRanking = $("#cityRanking").val();
        jsonData.provinceRanking = $("#provinceRanking").val();
        jsonData.nationalRanking = $("#nationalRanking").val();
        jsonData.id = $("#id").val();
        for (var i = 0; i < idFlag; i++) {
            var matchTime = matchTime + i;
            var matchName = matchName + i;
            var indId = indId + i;
            var ranking = ranking + i;
            var integral = integral + i;
            indId = $("#indId" + i).val();
            matchTime = new Date($("#matchTime" + i).val()).getTime();
            matchName = $("#matchName" + i).val();
            ranking = $("#ranking" + i).val();
            integral = $("#integral" + i).val();
            bb += indId + "," + matchTime + "," + matchName + "," + ranking + "," + integral + "-";
        }
        $.ajax({
            type: "POST", //提交方式
            traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
            url: "${base}/team/update",
            data: {param1: JSON.stringify(jsonData), param2: bb},
            success: function (data) {
                if (data.code === 0) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/team/selectMyPage'//数据接口
                        , where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                } else {
                    layer.msg(data.msg)
                }
            }
        });

    }


</script>

</body>
</html>
